<?php

use yii\db\Migration;

/**
 * Handles adding columns to table `{{%event}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%organization_branch}}`
 */
class m240523_114646_add_id_organization_branch_column_to_event_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->addColumn('{{%event}}', 'id_organization_branch', $this->integer());

        // creates index for column `id_organization_branch`
        $this->createIndex(
            '{{%idx-event-id_organization_branch}}',
            '{{%event}}',
            'id_organization_branch'
        );

        // add foreign key for table `{{%organization_branch}}`
        $this->addForeignKey(
            '{{%fk-event-id_organization_branch}}',
            '{{%event}}',
            'id_organization_branch',
            '{{%organization_branch}}',
            'id',
            'SET NULL'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%organization_branch}}`
        $this->dropForeignKey(
            '{{%fk-event-id_organization_branch}}',
            '{{%event}}'
        );

        // drops index for column `id_organization_branch`
        $this->dropIndex(
            '{{%idx-event-id_organization_branch}}',
            '{{%event}}'
        );

        $this->dropColumn('{{%event}}', 'id_organization_branch');
    }
}
